<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>SSO登录</title>
    <script src="./jquery-3.5.1.min.js"></script>
</head>
<body>

<form>
    <label for="username">用户名:</label>
    <input type="text" name="username" id="username"/>

    <label for="password">密码:</label>
    <input type="password" name="password" id="password"/>

    <button type="button" onclick="javascript:login()">登录</button>
</form>

</body>
<script>
    function login() {
        var username = $("#username").val();
        var password = $("#password").val();
        var service = getQueryString("service");
        console.log(username, password, service);
        //发起ajax请求
        var data = {
            username: username,
            password: password,
            service: service
        }
        $.post("/login", data, function (data, status) {
            window.location.href = data
        });
    }

    function getQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
        var r = window.location.search.substr(1).match(reg);  //获取url中"?"符后的字符串并正则匹配
        var context = "";
        if (r != null) context = r[2];
        reg = null;
        r = null;
        return context == null || context === "" || context === "undefined" ? "" : context;
    }
</script>
</html>